package com.wenyu.wenyuyuedu.adapter.circleAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.bean.circle.ShowCircleType;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/8.
 * 创建书圈类目的Gridview
 */

public class CreateCircleAdater extends BaseAdapter {
    private Context context;
    private List<ShowCircleType.InfoBean> info;
    private View view;
    private int currentItem = -1;

    public CreateCircleAdater(Context context) {
        this.context = context;
        info = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return info.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyCreateCirlceHolder holder = null;
        if (view == null) {
            holder = new MyCreateCirlceHolder();
            view = View.inflate(context, R.layout.create_circle_item, null);
            holder.circle_typename = (TextView) view.findViewById(R.id.circle_typename);
            view.setTag(holder);
        } else {
            holder = (MyCreateCirlceHolder) view.getTag();
        }
        if (currentItem == i) {
            holder.circle_typename.setText(info.get(i).getTitle());
            holder.circle_typename.setBackgroundResource(R.drawable.create_circle_select_shape);
            holder.circle_typename.setTextColor(context.getResources().getColor(R.color.white));
        } else {
            holder.circle_typename.setText(info.get(i).getTitle());
            holder.circle_typename.setBackgroundResource(R.drawable.create_circle_shape);
            holder.circle_typename.setTextColor(context.getResources().getColor(R.color.heise));
        }

        return view;
    }

    class MyCreateCirlceHolder {
        TextView circle_typename;
    }
    public void getSeletItem(int position) {
        this.currentItem = position;
    }

    public void addAll(List<ShowCircleType.InfoBean> info) {
        this.info.clear();
        this.info.addAll(info);
        notifyDataSetChanged();
    }

    public List<ShowCircleType.InfoBean> getList() {
        return info;
    }
}
